<template>
  <div class="app-container">
    <el-card class="box-card" shadow="hover">
      <!-- 民政数据模块 -->
      <div class="module-section">
        <div class="module-header">
          <i class="el-icon-office-building"></i>
          <span class="module-title">民政数据</span>
        </div>
        <el-row :gutter="20" class="module-content">
          <el-col
            :xs="24"
            :sm="12"
            :md="8"
            :lg="6"
            v-for="(value, key) in mzSingle"
            :key="key"
          >
            <div class="info-item">
              <span class="info-label">{{ getMzLabel(key) }}：</span>
              <span class="info-value">{{ value || "--" }}</span>
            </div>
          </el-col>
        </el-row>
      </div>

      <!-- 卫健数据模块 -->
      <div class="module-section">
        <div class="module-header">
          <i class="el-icon-first-aid-kit"></i>
          <span class="module-title">卫健数据</span>
        </div>
        <el-row :gutter="20" class="module-content">
          <el-col
            :xs="24"
            :sm="12"
            :md="8"
            :lg="6"
            v-for="(value, key) in wjSingle"
            :key="key"
          >
            <div class="info-item">
              <span class="info-label">{{ getWjLabel(key) }}：</span>
              <span class="info-value">{{ value || "--" }}</span>
            </div>
          </el-col>
        </el-row>
      </div>

      <!-- 公安数据模块 -->
      <div class="module-section">
        <div class="module-header">
          <i class="el-icon-money"></i>
          <span class="module-title">公安数据</span>
        </div>
        <el-row :gutter="20" class="module-content">
          <el-col
            :xs="24"
            :sm="12"
            :md="8"
            :lg="6"
            v-for="(value, key) in gaSingle"
            :key="key"
          >
            <div class="info-item">
              <span class="info-label">{{ getGaLabel(key) }}：</span>
              <span class="info-value">{{ value || "--" }}</span>
            </div>
          </el-col>
        </el-row>
      </div>
    </el-card>
  </div>
</template>

<script>
import { getList } from "@/api/system/list";

export default {
  name: "List",
  data() {
    return {
      // 表单参数
      form: {},
      // 民政数据
      mzSingle: {},
      // 卫健数据
      wjSingle: {},
      // 公安数据
      gaSingle: {},
      // 字段映射配置
      fieldLabels: {
        mz: {
          szbhMz: "逝者编号",
          hhsjMz: "火化时间",
          rgsjMz: "入馆时间",
          szxmMz: "逝者姓名",
          xbMz: "性别",
          nlMz: "年龄",
          zjlxMz: "证件类型",
          zjhmMz: "证件号码",
          hkszdMz: "户口所在地",
          szdzMz: "生前住址",
          swrqMz: "死亡日期",
          swyyMz: "死亡原因",
          cbrxmMz: "承办人姓名",
          lxdhMz: "联系电话",
          gxMz: "与逝者关系",
          slryMz: "受理人员",
        },
        wj: {
          bgdqmcWj: "报告地区名称",
          bgbhWj: "报告卡编号",
          tbdwdmWj: "填报单位代码",
          tbdwmcWj: "填报单位名称",
          szxmWj: "死者姓名",
          xbWj: "性别",
          zjlxWj: "证件类型",
          zjhmWj: "证件号码",
          csrqWj: "出生日期",
          mzWj: "民族",
          szxxdzWj: "生前详细地址",
          hjxxdzWj: "户籍详细地址",
          swrqWj: "死亡日期",
          swddWj: "死亡地点",
          jtxmWj: "可联系的家属姓名",
          jtdhWj: "家属联系电话",
        },
        ga: {
          xmGa: "姓名",
          xbGa: "性别",
          sfzhGa: "身份证号",
          hjszdGa: "户籍所在地/现住址",
          jslxfsGa: "家属联系方式",
          swsjGa: "死亡时间",
          swyyGa: "死亡原因",
        },
      },
      id: null,
    };
  },
  created() {
    this.id = this.$route.query.id;
    this.handleInfo();
  },
  activated() {
    this.id = this.$route.query.id;
    this.handleInfo();
  },
  methods: {
    handleInfo() {
      getList(this.id)
        .then((response) => {
          this.form = response.data;
          // 初始化各模块数据
          this.mzSingle = response.data.mzSingle || {};
          this.wjSingle = response.data.wjSingle || {};
          this.gaSingle = response.data.gaSingle || {};
        })
        .catch((error) => {
          console.error("获取数据失败:", error);
          this.$message.error("数据加载失败");
        });
    },

    // 获取民政字段标签
    getMzLabel(key) {
      return this.fieldLabels.mz[key] || key;
    },

    // 获取卫健字段标签
    getWjLabel(key) {
      return this.fieldLabels.wj[key] || key;
    },

    // 获取公安字段标签
    getGaLabel(key) {
      return this.fieldLabels.ga[key] || key;
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 84px);
}

.box-card {
  border-radius: 12px;
  border: none;

  ::v-deep .el-card__body {
    padding: 0;
  }
}

.module-section {
  padding: 24px;
  border-bottom: 1px solid #ebeef5;

  &:last-child {
    border-bottom: none;
  }

  &:nth-child(1) {
    .module-header {
      background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%);
    }
  }

  &:nth-child(2) {
    .module-header {
      background: linear-gradient(135deg, #a1c4fd 0%, #c2e9fb 100%);
    }
  }

  &:nth-child(3) {
    .module-header {
      background: linear-gradient(135deg, #fcb69f 0%, #ffecd2 100%);
    }
  }
}

.module-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  margin-bottom: 20px;
  border-radius: 8px;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

  i {
    font-size: 20px;
    margin-right: 12px;
  }

  .module-title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 1px;
  }
}

.module-content {
  margin: 0 -10px;
}

.info-item {
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
  padding: 0 10px;

  .info-label {
    font-size: 13px;
    color: #909399;
    margin-bottom: 4px;
    font-weight: 500;
    line-height: 1.4;
  }

  .info-value {
    font-size: 14px;
    color: #303133;
    font-weight: 500;
    line-height: 1.5;
    word-break: break-all;
    min-height: 22px;
    padding: 4px 8px;
    background-color: #f8f9fa;
    border-radius: 4px;
    border-left: 3px solid #409eff;
  }
}

// 响应式设计
@media (max-width: 768px) {
  .app-container {
    padding: 12px;
  }

  .module-section {
    padding: 16px;
  }

  .module-header {
    padding: 12px 16px;

    i {
      font-size: 18px;
    }

    .module-title {
      font-size: 16px;
    }
  }

  .info-item {
    margin-bottom: 12px;

    .info-label {
      font-size: 12px;
    }

    .info-value {
      font-size: 13px;
    }
  }
}

// 动画效果
.module-section {
  animation: fadeInUp 0.6s ease-out;

  &:nth-child(2) {
    animation-delay: 0.1s;
  }

  &:nth-child(3) {
    animation-delay: 0.2s;
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

// 悬停效果
.info-item:hover {
  .info-value {
    background-color: #e6f7ff;
    transform: translateX(4px);
    transition: all 0.3s ease;
  }
}

// 空数据样式
.info-value:empty::before {
  content: "--";
  color: #c0c4cc;
}
</style>
